package com.itheima.huikebackend.controller;

import com.itheima.huikebackend.common.R;
import com.itheima.huikebackend.common.Result;
import com.itheima.huikebackend.dto.ActivityCreateDTO;
import com.itheima.huikebackend.dto.TbActivityDTO;
import com.itheima.huikebackend.entity.TbActivity;
import com.itheima.huikebackend.service.TbActivityService;
import com.itheima.huikebackend.vo.TbActivityPageVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/clues/activity")
public class TbActivityController {

    private final TbActivityService tbActivityService;


    /**
     * 列表
     *
     * @param tbActivityDTO 结核活动dto
     * @return {@link R}<{@link Map}<{@link String},{@link Object}>>
     */
    @GetMapping("/list")
    public R<Map<String,Object>>list(TbActivityDTO tbActivityDTO){
        Map map = tbActivityService.list(tbActivityDTO);
        return R.success(map);
    }

    /**
     * 创建
     *
     * @param activityCreateDTO 活动创建dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> create(@RequestBody ActivityCreateDTO activityCreateDTO){
        tbActivityService.create(activityCreateDTO);
        return Result.success();
    }

    /**
     * 删除
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id){
        tbActivityService.delete(id);
        return Result.success();
    }

    /**
     * 查询
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/{id}")
    public Result<TbActivityPageVO> query(@PathVariable Long id){
        TbActivityPageVO tbActivityPageVO =  tbActivityService.query(id);
        return Result.success(tbActivityPageVO);
    }

    /**
     * 更新
     *
     * @param activityCreateDTO 活动创建dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping()
    public Result<?> update(@RequestBody ActivityCreateDTO activityCreateDTO){
        tbActivityService.update(activityCreateDTO);
        return Result.success();
    }


    /**
     * 列表中选择
     *
     * @param channel 通道
     * @return {@link Result}<{@link List}<{@link TbActivity}>>
     */
    @GetMapping("/listselect/{channel}")
    public Result<List<TbActivity>> listSelect(@PathVariable String channel){
        List<TbActivity> list = tbActivityService.listSelect(channel);
        return Result.success(list);
    }
}
